package com.text.viewpageviewpage;

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class ViewPage1 extends AppCompatActivity {


    ViewPager mViewPager;

    TextView mTvImageDesc;
    private List<ImageView> mImageList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view1);
        mViewPager = findViewById(R.id.view_pager);
        mTvImageDesc = findViewById(R.id.tv_image_desc);
        initView();
    }


    private void initView() {
        initData();
        CarouselAdapter mAdapter = new CarouselAdapter(mImageList, mViewPager);
        mViewPager.setAdapter(mAdapter);//第二步：设置viewpager适配器

    }


    /**
     * 第一步：初始化数据
     */
    //初始化图片轮播的图片
    private void initData() {
        int[] imageResIDs = {
                R.drawable.tablayout1text1,
                R.drawable.tablayout1text2,
                R.drawable.tablayout1text3,
                R.drawable.tablayout1text4,
        };
        mImageList = new ArrayList<>();
        ImageView iv;
        for (int i = 0; i < imageResIDs.length; i++) {
            iv = new ImageView(this);
            iv.setBackgroundResource(imageResIDs[i]);
            mImageList.add(iv);

        }
    }


}
